*******************************************************************************************************
* Replication file: "Insiders, outsiders, skills and preferences for social protection: evidence from a survey experiment in Argentina"
* Irene Menéndez González, January 2021
*******************************************************************************************************

clear
set more off

use apesw2_clean.dta, clear

* Only labour market participants

drop if P105_w2==3
drop if P105_w2==4
drop if P105_w2==5


* Generate variables
****************************************

* Dependent variable

* Dummy for support for non-contributory social policy 

gen supp1=.
replace supp1=. if P14_w2==3
replace supp1=0 if P14_w2==2
replace supp1=1 if P14_w2==1

lab def su1 0 "Registered workers" 1 "Non-registered workers"
lab val supp1 su1
lab var supp1 "Dummy: Support for outsiders"

* Support for non-contributory social policy - used to plot Fig A1

gen supp=.
replace supp=0 if P14_w2==3
replace supp=1 if P14_w2==2
replace supp=2 if P14_w2==1

lab def su 0 "Neither" 1 "Registered workers" 2 "Non-registered workers"
lab val supp su
lab var supp "Support for outsiders"


* Treatment and independent variables
*****************************************

* Treatment: respondent treatment status

gen treatment_dual=. 
replace treatment_dual=0 if RV1_w2=="a"
replace treatment_dual=1 if RV1_w2=="b"
replace treatment_dual=2 if RV1_w2=="c"
lab def _du 0 "Baseline" 1 "Poverty" 2 "Risk"
lab val treatment_dual _du
lab var treatment_dual "Base category: insider/outsider divide"

* Identifying insiders/outsiders

* Insider = formal sector worker in public or private sector that pays social security.
* Formal self-employed = self-employed/firmowner making contributions.
* Outsider = informal workers (self-employed, unpaid workers, informal firm-owners or private sector workers) and unemployed.
* If private sector worker and make no pension contributions, coded as informal.
* If firm-owner and if not subscribed to AFIP or if make irregular payments to AFIP, coded as informal.
* If self-employed and not subscribed to AFIP or if make irregular payments to AFIP, coded as informal.

* Formal/informal

gen dformal=.
replace dformal=1 if P107_w2==1  // State employee
replace dformal=1 if P107_w2==2 & P113_w2==1 // Private sector worker, pays social security
replace dformal=1 if P107_w2==3 & P115_w2==2 // Firmowner/shareholder, pays social security
replace dformal=1 if P107_w2==4 & P115_w2==2 // Self-employed, pays social security
replace dformal=0 if P107_w2==2 & P113_w2==2 // Private worker, not pay social security
replace dformal=0 if P107_w2==3 & P115_w2==1 | P115_w2==3 // Firm owner/shareholder, not pay/not regularly pay social security
replace dformal=0 if P107_w2==4 & P115_w2==1 | P115_w2==3 // Self employed, not pay/not regularly pay social security
replace dformal=0 if P107_w2==5 // Unpaid worker
replace dformal=0 if P105_w2==2 // Actively looking for work  
replace dformal=0 if P105_w2==6 // Not working and not looking for work

lab def df 0 "Informal" 1 "Formal" 
lab val dformal df
lab var dformal "Formal sector worker"

* Dummy insider/outsider 

gen dinsider=.
replace dinsider=1 if P107_w2==1 // State employee
replace dinsider=1 if P107_w2==2 & P113_w2==1 // Private sector worker, pays social security
replace dinsider=0 if P107_w2==3 & P115_w2==2 // Firmowner/shareholder, pays social security
replace dinsider=0 if P107_w2==4 & P115_w2==2 // Self-employed, pays social security
replace dinsider=0 if P107_w2==2 & P113_w2==2 // Private worker, not pay social security
replace dinsider=0 if P107_w2==3 & P115_w2==1 | P115_w2==3 // Firm owner/shareholder, not pay/not regularly pay social security
replace dinsider=0 if P107_w2==4 & P115_w2==1 | P115_w2==3 // Self employed, not pay/not regularly pay social security
replace dinsider=0 if P107_w2==5 // Unpaid worker
replace dinsider=0 if P105_w2==2 // Actively looking for work  
replace dinsider=0 if P105_w2==6 // Not working and not looking for work

lab def n 0 "Outsider" 1 "Insider"
lab val dinsider n
lab var dinsider "Insider" 

recode dinsider (0=1) (1=0), gen(doutsider) 
lab def t 0 "Insider" 1 "Outsider"
lab val doutsider t
lab var doutsider "Outsider"

* Categorical variable distinguishing between insider/outsider/formal self-employed
 
gen insider=.
replace insider=2 if P107_w2==1 // State employee
replace insider=2 if P107_w2==2 & P113_w2==1 // Private sector worker, pays social security
replace insider=1 if P107_w2==3 & P115_w2==2 // Firmowner/shareholder, pays social security
replace insider=1 if P107_w2==4 & P115_w2==2 // Self-employed, pays social security
replace insider=0 if P107_w2==2 & P113_w2==2 // Private worker, not pay social security
replace insider=0 if P107_w2==3 & P115_w2==1 | P115_w2==3 // Firm owner/shareholder, not pay/not regularly pay social security
replace insider=0 if P107_w2==4 & P115_w2==1 | P115_w2==3 // Self employed, not pay/not regularly pay social security
replace insider=0 if P107_w2==5 // Unpaid worker
replace insider=0 if P105_w2==2 // Actively looking for work  
replace insider=0 if P105_w2==6 // Not working and not looking for work

lab def e 0 "Outsider" 1 "Formal employed" 2 "Insider"
lab val insider e
lab var insider "Insider" 

recode insider (2=1) (0 1=0), gen(ins)
lab def _in 0 "Other" 1 "Insider"
lab val ins _in
lab var ins "Insider"

recode insider (0=2) (1=1) (2=0), gen(outsider)
lab def _w 0 "Insider" 1 "Formal self-employed" 2 "Outsider"
lab val outsider _w
lab var outsider "Outsider"

* Distinguishing between formal public and private workers

gen cinsider=.
replace cinsider=3 if P107_w2==1 // State employee
replace cinsider=2 if P107_w2==2 & P113_w2==1 // Private sector worker, pays social security
replace cinsider=1 if P107_w2==3 & P115_w2==2 // Firmowner/shareholder, pays social security
replace cinsider=1 if P107_w2==4 & P115_w2==2 // Self-employed, pays social security
replace cinsider=0 if P107_w2==2 & P113_w2==2 // Private worker, not pay social security
replace cinsider=0 if P107_w2==3 & P115_w2==1 | P115_w2==3 // Firm owner/shareholder, not pay/not regularly pay social security
replace cinsider=0 if P107_w2==4 & P115_w2==1 | P115_w2==3 // Self employed, not pay/not regularly pay social security
replace cinsider=0 if P107_w2==5 // Unpaid worker
replace cinsider=0 if P105_w2==2 // Actively looking for work  
replace cinsider=0 if P105_w2==6 // Not working and not looking for work

lab def _c 0 "Unemployed/informal" 1 "Self employed formal" 2 "Private formal" 3 "State formal"
lab val cinsider _c
lab var cinsider "Insider"

recode cinsider (3=0) (0=1) (1=2) (2=3), gen(private) 
lab def _er 0 "State employee" 1 "Outsider" 2 "Formal self-employed" 3 "Private employee"
lab val private _er
lab var private "Private formal worker"

* Skill level: based on edu

lab def _ude 0 "No formal/incomplete primary" 1 "Complete primary" 2 "Incomplete secondary" 3 "Complete secondary" 4 "Incomplete tertiary" 5 "Complete tertiary"
lab val edu _ude
lab var edu "Education"

gen prim=.
replace prim=1 if edu==0 // 0 = Without formal education or incomplete primary,
replace prim=1 if edu==1 // 1 = Complete primary
replace prim=0 if edu==2 // 2 = Incomplete secondary
replace prim=0 if edu==3 // 3 = Complete secondary
replace prim=0 if edu==4 // 4 = Incomplete tertiary or university
replace prim=0 if edu==5 // 5 = Complete tertiary or university

lab def p 0 "Other" 1 "Primary"
lab val prim p
lab var prim "Primary education"

gen sec=.
replace sec=1 if edu==0 // 0 = Without formal education or incomplete primary,
replace sec=1 if edu==1 // 1 = Complete primary
replace sec=1 if edu==2 // 2 = Incomplete secondary
replace sec=1 if edu==3 // 3 = Complete secondary
replace sec=0 if edu==4 // 4 = Incomplete tertiary or university
replace sec=0 if edu==5 // 5 = Complete tertiary or university

lab def _sc 0 "Other" 1 "Primary and secondary"
lab val sec _sc
lab var sec "Primary and secondary education"

gen insec=.
replace insec=1 if edu==0 // 0 = Without formal education or incomplete primary,
replace insec=1 if edu==1 // 1 = Complete primary
replace insec=1 if edu==2 // 2 = Incomplete secondary
replace insec=0 if edu==3 // 3 = Complete secondary
replace insec=0 if edu==4 // 4 = Incomplete tertiary or university
replace insec=0 if edu==5 // 5 = Complete tertiary or university

lab def _ic 0 "Other" 1 "Up to incomplete secondary"
lab val insec _ic
lab var insec "Up to incomplete secondary"

gen tert=.
replace tert=0 if edu==0 // 0 = Without formal education or incomplete primary,
replace tert=0 if edu==1 // 1 = Complete primary
replace tert=0 if edu==2 // 2 = Incomplete secondary
replace tert=0 if edu==3 // 3 = Complete secondary
replace tert=1 if edu==4 // 4 = Incomplete tertiary or university
replace tert=1 if edu==5 // 5 = Complete tertiary or university

lab def _t 0 "Other" 1 "Tertiary"
lab val tert _t
lab var tert "Tertiary education"

* Main interaction term

* Low-skilled insiders

gen lsi=.
replace lsi=2 if insider==2 & sec==1 // Low skill insider (primary and secondary)
replace lsi=1 if insider==0 // Outsider 
replace lsi=0 if insider==2 & sec==0 // high-skill insider (tertiary)

lab def _si 0 "High-skill insider" 1 "Outsider" 2 "Low-skill insider"
lab val lsi _si
lab var lsi "Low skill insider"

* Low-skilled formal workers

gen lsf=.
replace lsf=2 if dformal==1 & sec==1 // Low-skill formal
replace lsf=1 if dformal==0 // Informal/unemployed
replace lsf=0 if dformal==1 & sec==0 // High-skill formal

lab def _f 0 "High-skill formal" 1 "Outsider" 2 "Low-skill formal"
lab val lsf _f
lab var lsf "Low skill formal"

* Low-skilled private sector workers

gen lsp=.
replace lsp=1 if private==3 & sec==1 // Low-skill private formal workers
replace lsp=0 if private==3 & sec==0 // High-skill private formal workers

lab def s 0 "High skilled private" 1 "Low-skill private"
lab val lsp s
lab var lsp "Low skill private formal"

gen lspub1=.
replace lspub1=3 if private==3  & sec==1 // Low-skill private
replace lspub1=0 if private==3  & sec==0 // High-skill private
replace lspub1=5 if private==0  & sec==1 // Low-skill public
replace lspub1=4 if private==0  & sec==0 // High-skill public
replace lspub1=2 if private==2 // Formal self-employed
replace lspub1=1 if private==1 // Outsiders

lab def _b 0 "High-skill private" 1 "Outsiders" 2 "Formal self-employed" 3 "Low-skill private" 4 "High-skill public" 5 "Low-skill public"
lab val lspub1 _b
lab var lspub1 "Low skill private"

* Insiders with up to incomplete secondary

gen lsi1=.
replace lsi1=2 if insider==2 & insec==1 // Low-skill insider (primary and incomplete secondary)
replace lsi1=1 if insider==0 // Outsider
replace lsi1=0 if insider==2 & insec==0 // High-skill insider (complete secondary and tertiary)

lab def _inc 0 "High-skill insider" 1 "Outsider" 2 "Low-skill insider"
lab val lsi1 _inc
lab var lsi1 "Low skill insider"

* Disaggregating insiders and outsiders, by skill level

gen ioskill=.
replace ioskill=0 if insider==2 & sec==0 // high-skill insider
replace ioskill=1 if insider==2 & sec==1 // low-skill insider 
replace ioskill=2 if insider==0 & sec==0 // high-skill outsider
replace ioskill=3 if insider==0 & sec==1 // low-skill outsider

lab def io 0 "High-skill insider" 1 "Low-skill insider" 2 "High-skill outsider" 3 "Low-skill outsider"
lab val ioskill io
lab var ioskill "Low skill outsider"

* To graph mean predicted values of support as in Fig. 1: outsider > low-skill insider > high-skill insider

gen predsupp=.
replace predsupp=0 if lsi==1 
replace predsupp=1 if lsi==2 
replace predsupp=2 if lsi==0

lab def ps 0 "Outsider" 1 "Low-skilled insider" 2 "High-skilled insider"
lab val predsupp ps
lab var predsupp "Insiders/outsiders" 

* To graph mean levels of support as in Fig A1: outsider > low-skill insider > high-skill insider

gen meansupp=. 
replace meansupp=0 if lsi==1
replace meansupp=1 if lsi==2
replace meansupp=2 if lsi==0

lab def ms 0 "Outsider" 1 "Low-skilled insider" 2 "High-skilled insider"
lab val meansupp ms
lab var meansupp "Insiders/outsiders"


* Pre-determined variables
***********************************

* Age = edad

tab edad
rename edad age

gen dage=.
replace dage=1 if age>40 // median=40
replace dage=0 if age<=40

lab def da 0 "Younger" 1 "Older"
lab val dage da
lab var dage "Older workers"

* Gender

gen gender=.
replace gender=0 if sexo==1
replace gender=1 if sexo==2

lab def gend 0 "Male" 1 "Female" 
lab val gender gend
lab var gender "Gender"

* Province 

lab def v 1 "CF" 2 "Buenos Aires" 3 "Chaco" 4 "Cordoba" 5 "Corrientes" 6 "Entre Rios" 7 "Jujuy" 8 "La Rioja" 9 "Mendoza" 10 "Neuquen" 11 "Rio Negro" 12 "Santa Fe" 13 "Santiago del Estero" 14 "Tucuman"
lab val provincia v
lab var provincia "Province"


* Other variables
*********************************

* Income

gen dses=.
replace dses=1 if ses<=3 // Low income
replace dses=0 if ses>3 // High income

lab def se 0 "High income" 1 "Low income"
lab val dses se
lab var dses "Income dummy"

* Low-income insider

gen poorins=.
replace poorins=2 if dses==1 & insider==2 // Low-income insider
replace poorins=1 if insider==0 // Outsider
replace poorins=0 if dses==0 & insider==2 // High-income insider

lab def _pi 0 "Wealthy insider" 1 " Outsider" 2 "Poor insider"
lab val poorins _pi
lab var poorins "Low-income insider"

* Insider with negative pocketbook evaluations (using subjective economic evaluation as proxy for income) 

gen subj=.
replace subj=1 if P6_w2>=3 // Negative subj evaluations
replace subj=0 if P6_w2<3 //  Positive subj evaluations 

lab def sj 0 "Positive evaluation" 1 "Negative evaluation"
lab val subj sj
lab var subj "Subjective economic evaluation"

gen poorins2=.
replace poorins2=2 if subj==1 & insider==2 // insider with negative pocketbook evaluations 
replace poorins2=1 if insider==0 // Outsider
replace poorins2=0 if subj==0 & insider==2 // insider with positive pocketbook evaluations

lab def _p 0 "Negative evaluation" 1 " Outsider" 2 "Positive evaluation"
lab val poorins2 _p
lab var poorins2 "Insider pocketbook evaluation"

* Political knowledge

gen knowledge=.
replace knowledge=0 if knowledge_w1==0
replace knowledge=0 if knowledge_w1==1
replace knowledge=1 if knowledge_w1==2
replace knowledge=1 if knowledge_w1==3

replace knowledge=0 if knowledge_w2==0
replace knowledge=0 if knowledge_w2==1
replace knowledge=1 if knowledge_w2==2
replace knowledge=1 if knowledge_w2==3

lab def _k 0 "Low" 1 "High"
lab val knowledge _k
lab var knowledge "Political knowledge"

* Union membership 

tab tipo P103_w2 
tab tipo P29_4

gen union=.
replace union=1 if P103_w2==1    
replace union=0 if P103_w2==0 

replace union=1 if P29_4==1 
replace union=1 if P29_4==2 
replace union=1 if P29_4==3
replace union=0 if P29_4==4

lab def un 0 "Not member" 1 "Member"
lab val union un
lab var union "Union membership"

* Wealth measure: ses index

* Ideology
 
gen ideo=.
replace ideo=0 if P39_w2==0 
replace ideo=1 if P39_w2==1 
replace ideo=2 if P39_w2==2 
replace ideo=3 if P39_w2==3 
replace ideo=4 if P39_w2==4 
replace ideo=5 if P39_w2==5 
replace ideo=6 if P39_w2==6 
replace ideo=7 if P39_w2==7 
replace ideo=8 if P39_w2==8 
replace ideo=9 if P39_w2==9 
replace ideo=10 if P39_w2==10

replace ideo=0 if P36==0 
replace ideo=1 if P36==1 
replace ideo=2 if P36==2 
replace ideo=3 if P36==3 
replace ideo=4 if P36==4 
replace ideo=5 if P36==5 
replace ideo=6 if P36==6 
replace ideo=7 if P36==7 
replace ideo=8 if P36==8 
replace ideo=9 if P36==9 
replace ideo=10 if P36==10  

gen dideo=.
replace dideo=1 if ideo<6
replace dideo=0 if ideo>=6

lab def di 0 "Right" 1 "Left"
lab val dideo di
lab var dideo "Ideology"

* Peronist vote

gen vote=.
replace vote=1 if P27_abierta_w2==1 // Daniel Scioli (PJ/FPV)
replace vote=1 if P27_abierta_w2==3 // Sergio Massa (Frente UNA)
replace vote=0 if P27_abierta_w2==2 // Mauricio Macri (PRO/Cambiemos)
replace vote=0 if P27_abierta_w2==4 // Margarita Stolbizer (GEN/Alianza Progresistas)
replace vote=0 if P27_abierta_w2==5 // Adolfo Rodriguez Saa (Alianza Compromiso Federal/Peronismo disidente)
replace vote=0 if P27_abierta_w2==6 // Nicolas del Cano (Partido Trabajdores Socialistas/Frente de Izquierda)

lab def _vo 1 "Peronist" 0 "Other"
lab val vote _vo
lab var vote "Peronist vote"

* Clientelism

gen client_barrio=.
replace client_barrio=1 if P52_w2==1
replace client_barrio=0 if P52_w2==0

lab def _ba 1 "Neighbours received favour from candidate" 0 "Neighbours not received favour"
lab val client_barrio _ba
lab var client_barrio "Clientelism"

gen client_ind=.
replace client_ind=1 if P54_w2==1
replace client_ind=0 if P54_w2==0

lab def _cli 1 "Received favour from candidate" 0 "Not received favour"
lab val client_ind _cli
lab var client_ind "Clientelism"

gen client=.
replace client=1 if client_barrio==1 | client_ind==1
replace client=0 if client_barrio==0 & client_ind==0

lab def cl 1 "Received favours" 0 "Not received favours"
lab val client cl
lab var client "Clientelism"

* Subjective evaluation of Cristina Fernandez de Kirchner as proxy for Peronist vote (pre-treatment)

gen cris=.
replace cris=1 if P2_w2==1
replace cris=1 if P2_w2==2
replace cris=0 if P2_w2==3
replace cris=0 if P2_w2==4
replace cris=0 if P2_w2==5
lab def c_ 0 "Not Peronist" 1 "Peronist"
lab val cris c_
lab var cris "Support for Cristina"


save apesw2_ready.dta, replace
